#pragma once

#include "Object/Object.h"
#include "Widgets/CanvasWidget.h"
#include "EditorScriptToken.h"
#include "EditorScriptFile.m.h"

class RTextDocument;
class IEditorScriptIdentifier;

RCLASS(ExtraHeader= "Document/TextDocument.h")
class REditorScriptFile : public RObject //, public ITickable
{
    ROBJECT

public:
    void BindDocument(TSharedObjectPtr<RTextDocument> InDocument);

    const TVector<SColorfulTextColor>& GetColors() const
    {
        return Colors;
    }

protected:
    RFIELD()
    TSharedObjectPtr<RTextDocument> TextDocument;


public:

protected:

    bool bIsDirty = true;
    //TVector<int64_t> DirtyLines;

    RFUNCTION()
    void OnTextChanged();


    void UpdateSyntaxTokens();

    void UpdateColors();

    TVector<SEditorScriptToken> Tokens;

    //hold the identifier, keep identifiers alive
    TVector<std::shared_ptr<IEditorScriptIdentifier>> Identifiers;

    TVector<SColorfulTextColor> Colors;

    friend class RScriptIntelliSenseSubsystem;
};